{  Statement: http://acmp.ru/?main=task&id_task=35
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
    i,n:longint;
    x,y:int64;

begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n);
for i:=1 to n do begin
    read(x,y);
    writeln(19 * y + (x + 239)*(x + 366) div 2);
end;
end.